import numpy as np
import pandas as pd
from flask import current_app

from app.services.models.file_model import FileModel


class ShaoJieTemModel5Min(FileModel):

    def __init__(self):
        super().__init__(model_name="shaojie_5mins_temperature_model")

    def process(self, temp_model_input):
        try:
            params_dict = {}
            for key, value in temp_model_input.__dict__.items():
                tlist = []
                tlist.append(value)
                params_dict[key] = tlist

            input_df = pd.DataFrame.from_dict(params_dict)
            input_df = input_df.loc[0:1, [
                                             "CG_SJ_SJJ_SJ02_YDWDB",
                                             "CG_SJ_SJJ_SJ02_YDWDN",
                                             "CG_SJ_SJJ_SJ02_SJJXS",
                                             "CG_SJ_SJJ_SJ02_FQWD13",
                                             "CG_SJ_SJJ_SJ02_JGJXS",
                                             "CG_SJ_SJJ_SJ02_FQWD01",
                                             "CG_SJ_SJJ_SJ02_FQWD11",
                                             "CG_SJ_SJJ_SJ02_FJFL01",
                                             "CG_SJ_SJJ_SJ02_FJFL02",
                                             "CG_SJ_SJJ_SJ02_ZKD05",
                                             "CG_SJ_SJJ_SJ02_YGJXS"
                                         ]]
            predict_location = self.model_instance.predict(input_df)
            response = predict_location[0].astype(np.unicode)
            response = float(response)+80
            return response

        except Exception as e:
            # pass
            current_app.logger.info(e)


# 用导出module的方法创建单例
shaojie_temp_5m_model = ShaoJieTemModel5Min()
